using System;
using logging;

interface IGamePlayer{
    void playing();
    void upgrade();
}

class GamePlayerProxy: IGamePlayer{
    private GamePlayer _real;
    public GamePlayerProxy(GamePlayer real_player){
        if(real_player == null)  throw new Exception("No real player found.");
        _real = real_player;
    }

    public void playing(){
        _real.playing();
    }
    public void upgrade(){
        _real.upgrade();
    }
}

class GamePlayer: IGamePlayer{
    protected string _name;
    public GamePlayer(string name){
        this._name = name;
    }

    public virtual void playing(){
        Log.print(_name + "执行任务");
    }
    public virtual void upgrade(){
        Log.print(_name + "升级啦！");
    }
}

class ForcedGamePlayer: GamePlayer{
    public ForcedGamePlayer(string name): base(name){ }

    private GamePlayerProxy _proxy;
    public GamePlayerProxy proxy{
        get{
            this._proxy = new GamePlayerProxy(this);
            return this._proxy;
        }
    }

    private bool isMyProxy(){  // proxy check
        if(this._proxy == null){
            Log.print("请使用指定的代理访问");
            return false;
        }else
            return true;
    }

    public override void playing(){
        if(isMyProxy())  // 强制代理
            base.playing();
    }
    public override void upgrade(){
        if(isMyProxy())  // 强制代理
            base.upgrade();
    }
}

class Demo{
    public static void Main(string[] args){
#if FORCED
        var player = new ForcedGamePlayer("Flora");
        GamePlayerProxy proxy = player.proxy;
        proxy.playing();
        proxy.upgrade();
#else
        IGamePlayer player = new GamePlayer("Bob");
        // these two method will return directly.
        player.playing();
        player.upgrade();
#endif
    }
}
